﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;
using CPN.PJN.Silverlight.UI.Controls;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CPN.PJN.UI.Controls.UnitTests
{
    [TestClass]
    public class WatermarkTextBoxUnitTests : SilverlightTest
    {
        const string GroupCommon = "CommonStates";
        const string GroupFocus = "FocusStates";
        const string GroupSelection = "SelectionStates";
        const string GroupWatermark = "WatermarkStates";
        const string StateDisabled = "Disabled";
        const string StateMouseOver = "MouseOver";
        const string StateNormal = "Normal";
        const string StateFocused = "Focused";
        const string StateUnfocused = "Unfocused";
        const string StateUnwatermarked = "Unwatermarked";
        const string StateWatermarked = "Watermarked";

        const string WatermarkElementName = "WatermarkContentControl";

        [TestMethod]
        [Description("Vérifie que les VisualStates existent")]
        public void UnitTest1_VisualStatesAreDefined()
        {
            IDictionary<string, string> visualStates = typeof(WatermarkTextBox).GetVisualStates();
            Assert.AreEqual(7, visualStates.Count);

            Assert.AreEqual<string>(GroupCommon, visualStates[StateNormal]);
            Assert.AreEqual<string>(GroupCommon, visualStates[StateMouseOver]);
            Assert.AreEqual<string>(GroupCommon, visualStates[StateDisabled]);

            Assert.AreEqual<string>(GroupFocus, visualStates[StateFocused]);
            Assert.AreEqual<string>(GroupFocus, visualStates[StateUnfocused]);

            Assert.AreEqual<string>(GroupWatermark, visualStates[StateUnwatermarked]);
            Assert.AreEqual<string>(GroupWatermark, visualStates[StateWatermarked]);
        }

        [TestMethod]
        [Description("Vérifie que les templates existent")]
        public void UnitTest2_TemplatePartsAreDefined()
        {
            IDictionary<string, Type> templateParts = typeof(WatermarkTextBox).GetTemplateParts();
            Assert.AreEqual(1, templateParts.Count);
            Assert.AreSame(typeof(ContentControl), templateParts[WatermarkElementName]);
        }

        [TestMethod]
        [Asynchronous]
        [Description("Vérifie que le contrôle est OK")]
        public void UnitTest3_WatermarkTextBoxInitialization()
        {
            var watermarkTextBox = new WatermarkTextBox();
            watermarkTextBox.Watermark = "Rechercher...";
            TestPanel.Children.Add(watermarkTextBox);
            TestComplete();
        }

        [TestMethod]
        [Asynchronous]
        [Description("Vérifie que le contrôle est désactivable")]
        public void UnitTest4_IsDisabled()
        {
            var watermarkTextBox = new WatermarkTextBox();
            watermarkTextBox.Watermark = "Rechercher...";
            TestPanel.Children.Add(watermarkTextBox);
            watermarkTextBox.IsEnabled = false;
            TestComplete();
        }
    }
}